var app = getApp();
Page({
  data: {
  	type:1,
  	list:[],
  	listlength:0
  },
  onLoad(options) {
  	var coll=wx.getStorageSync('coll');
  	this.setlist(coll)
  },
  setlist:function(coll){
  	var len=0;
  	for(var i in coll){
  		len++;
  	}
  	this.setData({
	    	list:coll,
	    	listlength:len
	  });
  },
  del:function(e){
  	var i=e.target.dataset.index
  	var coll=wx.getStorageSync('coll')
  	var that=this;
  	wx.showModal({
		  title: '删除',
		  content: '确定要删除吗？',
        success(res) {
            if (res.confirm) {
            	delete coll[i];  	
					  	that.setlist(coll)  	
					  	wx.setStorage({
								   key: "coll",
								   data: coll //需要存储的数据
							})
            }else if(res.cancel) {
          	}
       }
   })
  	
  	
  	
  },
  clear:function(){
  	var coll={}
  	var that=this;
  	wx.showModal({
		  title: '清空',
		  content: '确定要清空我的收藏吗？',
        success(res) {
            if (res.confirm) { 	
					  	that.setlist(coll)  	
					  	wx.setStorage({
								   key: "coll",
								   data: coll //需要存储的数据
							})
            }else if(res.cancel) {
          	}
       }
   })
  }
})